<template>
  <u-container-layout>
    <zlrt-table :p="ctx">
      <template v-slot:before>
        <zlrt-search :p="ctx"></zlrt-search>
        <div class="tool-bar">
          <el-button type="danger" v-hasPermit="['core:user:del']" icon="Delete" :disabled="!ctx.selected.length"
            @click="ctx.batchDelete()">
            批量删除
          </el-button>
          <span style="float:right">
            <el-button type="success" v-hasPermit="['core:user:list']" :loading="ctx.exportLoading" icon="Download"
              @click="ctx.export()">
              导出
            </el-button>
            <el-button type="primary" v-hasPermit="['core:user:save']" icon="Plus" @click="ctx.showEdit()">
              添加
            </el-button>
          </span>
        </div>
      </template>
      <template v-slot:disabled="scope">
        <template v-if="scope.row.username === 'admin'">
          <el-tag type="success">正常</el-tag>
        </template>
        <template v-else>
          <el-switch v-model="scope.row.disabled" :active-value="false" :inactive-value="true"
            @change="ctx.other.statusChanged(scope.row)" />
        </template>
      </template>
      <template v-slot:operation="scope">
        <template v-if="scope.row.username !== 'admin'">
          <el-button type="primary" v-hasPermit="['core:user:save']" link size="small" icon="Edit"
            @click="ctx.other.showEdit(scope.row)">
            编辑
          </el-button>
          <el-button type="danger" v-hasPermit="['core:user:del']" link size="small" icon="Delete"
            @click="ctx.del(scope.row.id)">
            删除
          </el-button>
        </template>
      </template>
      <template v-slot:after>
        <el-dialog v-model="ctx.editVisible" :title="ctx.editAction + ctx.title" width="600px" append-to-body
          :close-on-click-modal="false" @close="ctx.closeEdit()">
          <el-form :ref="(e) => ctx.formRef = e" :model="ctx.editData" :rules="ctx.rules" v-loading="ctx.editLoading"
            label-width="120px" class="demo-ruleForm">
            <el-row>
              <el-col :span="12">
                <el-form-item label="用户账号" prop="username">
                  <el-input v-model="ctx.editData.username" placeholder="请输入用户账号" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="密码" prop="password">
                  <el-input type="password" v-model="ctx.editData.password" show-password />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="姓名" prop="nickname">
                  <el-input v-model="ctx.editData.nickname" placeholder="请输入用户姓名" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="性别" prop="sex">
                  <el-select v-model="ctx.editData.sex" placeholder="请选择性别">
                    <el-option label="男" value="0" />
                    <el-option label="女" value="1" />
                    <el-option label="未知" value="2" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="手机号" prop="phone">
                  <el-input v-model="ctx.editData.phone" maxlength="11" placeholder="请输入手机号" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="邮箱" prop="email">
                  <el-input v-model="ctx.editData.email" placeholder="请输入邮箱" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="用户角色" prop="role">
                  <el-select v-model="ctx.editData.role" multiple placeholder="请选择角色">
                    <el-option v-for="ite in roleOptions" :key="ite.id" :label="ite.roleName" :value="ite.id" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="状态" prop="disabled">
                  <el-select v-model="ctx.editData.disabled" placeholder="请选择状态">
                    <el-option v-for="ite in disabledOptions" :key="ite.value" :label="ite.label" :value="ite.value" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="ctx.editVisible = false">取消</el-button>
              <el-button type="primary" @click="ctx.other.setRoles();ctx.save()">确定</el-button>
            </span>
          </template>
        </el-dialog>
      </template>
    </zlrt-table>

  </u-container-layout>
</template>

<script lang="ts" src="./user.ts">
</script>
